<template>
  <div class="app-container">
    <el-form :inline="true" ref="form" :model="form">
      <el-form-item label="地址">
        <el-input v-model="form.url"  placeholder="请输入内容"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">保存</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="searchHandler()">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="testServer()">验证</el-button>
      </el-form-item>      
    </el-form>
    <el-form :inline="true" :model="searchForm">
      <el-form-item label="地址">
        <el-input v-model="searchForm.url"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmitDB()">保存</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="searchDBHandler()">查询</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>

import { store } from '@/utils/electron/datastore/index'
import { postModel,getModelWhere } from '@/utils/electron/datastore/configMapper'
const logger  = require('@/utils/electron/index').Logger('aboutVersion')
import { message } from "@/api/login";
export default {
  data() {
    return {
      form: {
        type:'remoteUrl',
        url: "https://api-m.minicps.com",
        delivery: false
      }
      ,searchForm: {
        type:'remoteUrl'
        ,url: ''
      }
    };
  },
  methods: {
    onSubmit() {
      logger.info('[onSubmit保存配置信息]:',this.form)
      store.set('baseURL',this.form.url)
      this.$message({type: 'success',message:"设置成功!"});   
      
    }
    ,searchHandler(){
      logger.info('[searchHandler查询配置信息]:', this.searchForm);
      const baseURL =  store.get('baseURL')
      this.searchForm.url = baseURL
      this.$message({type: 'success',message: baseURL})    
    }
    ,testServer(){
       message().then((res) => {
        this.$alert(res.data, "提示", {
          confirmButtonText: "确定",
        });
      });
    }
    ,onSubmitDB(){
      this.form.id  = 1000
      logger.info('[onSubmitDB保存本地数据库配置信息]:',this.form)
      postModel(this.form)
      this.$message({type: 'success',message:"设置成功!"});  
    }
    ,searchDBHandler(){
       getModelWhere({id: 1000}).then(result => {
         logger.info('[searchDBHandler查询本地数据库配置信息]:',result.data[0]);
         this.$message({type: 'success',message: result.data[0].url})    
       })
      
    }
  }
};
</script>

<style scoped>
  .line {
    text-align: center;
  }
</style>

